import request from "@/utils/request";

import type { spuResType, proName, skuImgType, comSal, comThree } from "./type";

enum API {
    // 获取SPU属性
    GET_SPU_URL = "/admin/product/",
    // 获取品牌名称
    GET_PRUDUCT_NAME = "/admin/product/baseTrademark/getTrademarkList",
    // 获取SKU的图片
    GET_SKU_IMAGE = "/admin/product/spuImageList/",
    // SKU销售属性列表
    GET_SAL_LIST = "/admin/product/spuSaleAttrList/",
    // 尺寸 颜色等
    GET_SIZE_COLOR_PERSION = "/admin/product/baseSaleAttrList",
    // 更新和新增
    UPDATE_SPU = "/admin/product/updateSpuInfo",
    SAVE_SPU = "/admin/product/saveSpuInfo",

    // 删除SPU
    DELETE_SPU = "/admin/product/deleteSpu/",
}

export const getSpuUrl = (
    page: number,
    limit: number,
    category3Id: number | string | undefined
) =>
    request.get<any, spuResType>(
        API.GET_SPU_URL + `${page}/${limit}?category3Id=${category3Id}`
    );

export const getProName = () => request.get<any, proName>(API.GET_PRUDUCT_NAME);

export const getSkuImage = (spuId: number) =>
    request.get<any, skuImgType>(API.GET_SKU_IMAGE + spuId);

export const getSalList = (spuId: number) =>
    request.get<any, comSal>(API.GET_SAL_LIST + spuId);

export const getThree = () =>
    request.get<any, comThree>(API.GET_SIZE_COLOR_PERSION);

export const updateAndSave = (data:any) => {
    if (data.id) {
        return request.post<any, any>(API.UPDATE_SPU, data);
    } else { 
        return request.post<any, any>(API.SAVE_SPU, data);
    }
}

export const deleteSpu = (spuId:number) => request.delete<any,any>(API.DELETE_SPU+spuId)